如何在appp.js中調用app2.js中的數值
//appp.js
global.conflictVar = 1
node appp.js可以讀到 (若上述改成let conflictVar = 1 則讀不到)
const app2 = require("./app2Folder/app2"); //在目前位置下找到app2Folder資料夾中的app2.js後載入
//app2.js
const conflictVar = 10;
let GlobalVarInApp2 = 15;
module.exports = {
conflictVar,
testNum: 5,
GlobalVarInApp2, //若此處沒寫GlobalVarInApp2則appp.js讀不到此值
};
//appp.js
console.log(app2.testNum+app2.GlobalVarInApp2) // 20 可讀到testNum與GlobalVarInApp2
console.log(conflictVar); //1
console.log(app2.conflictVar); //10